<?php
/**
**名称:天猫折扣精品库的页面
**作用:天猫折扣精品库的页面
**作者:张剑 swordphp@126.com
**创建日期:2013-03-05
**最后修改日期:2013-03-13
**/
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
class index{
	public function __construct(){
		$this ->jihe_db = pc_base::load_model('jihe_model');
		$this ->item_db = pc_base::load_model('tmall_zhekou_model');
	}
	public function init(){
		ob_start();
		$pid_info = $this->jihe_db->get_one(array('short_name'=>'jizi_index'));
		$infos = $this->jihe_db->select(array('pid'=>$pid_info['id'],'is_display'=>1),'*','','order_id ASC');
		$tejia = $this->jihe_db->get_one(array('short_name'=>'tejia'));
		$baoyou = $this->jihe_db->get_one(array('short_name'=>'baoyou'));
		foreach($infos as $key=>$val){
			if($val['short_name'] == 'tejia'||$val['short_name'] == 'baoyou'){
				unset($infos[$key]);
				continue;
			}
		}
		$b_pid = $this->jihe_db->get_one(array('short_name'=>'bottom_keyword'));
		$bottom_keyword = $this->jihe_db->select(array('pid'=>$b_pid['id']),'*','','order_id DESC');
		$infos = array_chunk($infos,3);
		include template('s_gouwu','index');
		$data = ob_get_contents();
		$data = str_replace(APP_PATH,'./',$data);
		ob_clean();
		echo $data;
	}
	public function ji_sort(){
		$short_name = isset($_GET['sort'])?$_GET['sort']:'';
		$jizi_info = $this->jihe_db->get_one(array('short_name'=>$short_name));
		$jid = $jizi_info['id'];
		$now_title = $jizi_info['classname'];
		//底部的推荐集子数据
		$b_ids = $jizi_info['relate_j_id'];
		if($b_ids !=''){
			$b_infos = $this->jihe_db->select("id IN ($b_ids)",'id,classname,url');
		}
		//var_dump($b_infos);
		//集子数据
		if($jid != ''){
			$data = $this->item_db->select(array('j_id'=>$jid,'is_display'=>1),'detail_url,j_id,pic_path,price,pro_price,m_url,sole,item_title','0,100','add_time DESC,order_id DESC');
			$index_id = $this->jihe_db->get_one(array('short_name'=>'jizi_index'));
			$r_nav = $this->jihe_db->select(array('pid'=>$index_id['id']),'*','','order_id DESC');
			foreach($r_nav as $key=>$val){
				if($val['id'] == $jid) unset($r_nav[$key]);
			}
			foreach($data as $key=> $val){
				$data[$key]['m_url'] = $val['m_url'] == ''?$val['detail_url']:$val['m_url'];
				if($val['j_id'] == 6){
					$data[$key]['zhekou'] = round($val['pro_price']*10/$val['price'],1).'折';
				}else{
					unset($data[$key]['itemurl']);
				}
			}
			$data = array_chunk($data,10);
			//更多数据
			$infos = $data[0];
			unset($data[0]);
			$more_data = $data;
			include template('s_gouwu',$jizi_info['used_template']);
		}else{
			return false;
		}
	}
}